﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Catering.yl.Daily
{
    public partial class ProvideProduct : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            { 
                LoadForm();
            }
        }
        public void LoadForm()
        {
            try
            {
                DataTable dt_Plan = new Catering_Rules.ProvideProduct().GetList("").Tables[0];
                dt_Plan.Columns.Add("tempId");

                for (int i = 0; i < dt_Plan.Rows.Count; i++)
                {
                    dt_Plan.Rows[i]["tempId"] = i + 1;
                }
                this.Rep_PPlan.DataSource = dt_Plan;
                this.Rep_PPlan.DataBind();                
            }
            catch
            {

            }
        }
        [WebMethod]
        public static string Add(string PName, string PType, string PUint, string PNums,string PDesc)
        {
            Catering_Model.ProvideProduct _cp = new Catering_Model.ProvideProduct();
            _cp.SNumber = DateTime.Now.ToString("yyyyMMddHHmmss");
            _cp.PName = PName;
            _cp.PType = PType;
            _cp.PUint = PUint;
            _cp.PNums = PNums;
            _cp.PDesc = PDesc;            

            new Catering_Rules.ProvideProduct().Add(_cp);
            return "OK";
        }
        [WebMethod]
        public static ArrayList Get(string _id)
        {
            ArrayList al = new ArrayList();
            Catering_Model.ProvideProduct md = new Catering_Rules.ProvideProduct().GetModel(Convert.ToInt32(_id));
            al.Add(md.Id);
            al.Add(md.PName);
            al.Add(md.PType);
            al.Add(md.PUint);
            al.Add(md.PNums);
            al.Add(md.PDesc);
            return al;
        }
        [WebMethod]
        public static string Edit(string _id, string PName, string PType, string PUint, string PNums, string PDesc)
        {
            int id = 0;
            int areaid = 0;
            Int32.TryParse(_id, out id);
            if (id <= 0) return "NO";

            Catering_Model.ProvideProduct _CE = new Catering_Model.ProvideProduct();

            _CE.Id = id;
            _CE.PName = PName;
            _CE.PType = PType;
            _CE.PUint = PUint;
            _CE.PNums = PNums;
            _CE.PDesc = PDesc;
            new Catering_Rules.ProvideProduct().Update(_CE);

            return "OK";
        }
        protected void Rep_Plan_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                int delID = Convert.ToInt32(e.CommandArgument);
                if (new Catering_Rules.ProvideProduct().Delete(delID))
                {
                    this.LoadForm();
                }
            }
        }
    }
}